package com.example.hellodemo;

import androidx.appcompat.app.AppCompatActivity;

import android.os.Bundle;
import android.util.Log;
import android.view.MotionEvent;
import android.view.View;
import android.widget.Button;
import android.widget.TextView;
import android.widget.Toast;

import com.example.hellodemo.widget.MyButton;

public class ButtonActivity extends AppCompatActivity {
    private Button btn;
    private MyButton myButton;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_button);
        btn = findViewById(R.id.btn_three);
        myButton = findViewById(R.id.myButton);


        myButton.setOnTouchListener(new View.OnTouchListener() {
            @Override
            public boolean onTouch(View v, MotionEvent event) {
                switch (event.getAction()){
                    case MotionEvent.ACTION_DOWN:
                        break;
                    case MotionEvent.ACTION_UP:
                        break;
                }
                // false 不接受事件,则判断是否有回调处理，如果有则传给回调处理，如果没有 传递给下一级组件处理。 true 接受事件。事件不再向下传递

                Log.d("监听机制处理","...onTouch...ACTION_UP");

                return false;
            }
        });

        myButton.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                Log.d("监听机制处理","...OnClickListener...ACTION_UP");

            }
        });

    }

//    @Override
//      public boolean onTouchEvent(MotionEvent event) {
//        Log.d("activity","onTouchEvent");
//        return super.onTouchEvent(event);
//    }

    public  void showToast(View view){
        Toast.makeText(this,"btn被点击了",Toast.LENGTH_SHORT).show();
    }
}
